package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjFactoryUser;
import com.zb.extend.FactoryUserExtend;
import com.zb.mapper.ZjFactoryUserMapper;
import com.zb.service.ZjFactoryUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 厂商用户表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2024-03-27
 */
@Service
public class ZjFactoryUserServiceImpl extends ServiceImpl<ZjFactoryUserMapper, ZjFactoryUser> implements ZjFactoryUserService {
    @Resource
    private ZjFactoryUserMapper factoryUserMapper;

    // 保存关联品牌厂商的客户
    @Override
    public void save(Long custAccId, Long factoryId, Long userId) {
        if (null == factoryId || factoryId == 0) {
            return;
        }
        if (null != factoryUserMapper.existByFactoryIdAndUserId(factoryId, userId)){
            return;
        }
        ZjFactoryUser factoryUser = new ZjFactoryUser();
        factoryUser.setId(IdWorker.getId());
        factoryUser.setCustAccId(custAccId);
        factoryUser.setFactoryId(factoryId);
        factoryUser.setUserId(userId);
        this.save(factoryUser);
    }

    // 根据客户ID获取关联的品牌厂商
    @Override
    public List<FactoryUserExtend> getByUserIds(List<Long> userIds) {
        if (CollectionUtil.isEmpty(userIds)) {
            return new ArrayList<>();
        }
        return factoryUserMapper.getByUserIds(userIds);
    }
}
